package com.sinochem.yunlian.ship.base.biz;

import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.sinochem.yunlian.ship.api.vo.uc.UcUserInfo;
import com.sinochem.yunlian.ship.base.entity.BsPortalNews;
import com.sinochem.yunlian.ship.base.mapper.BsPortalNewsMapper;
import com.sinochem.yunlian.ship.base.vo.request.FindPortalNewVo;
import com.sinochem.yunlian.ship.base.vo.request.PortalNewsVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;

/**
 * Created by jayway on 2017/12/9.
 */
@Service
public class BsPortalNewBiz {
    @Autowired
    private BsPortalNewsMapper newsMapper;

    public void addNews(PortalNewsVo vo, UcUserInfo userInfo){
        BsPortalNews news = new BsPortalNews();
        BeanUtils.copyProperties(vo,news);
        news.setCreateBy(userInfo.getId());
        news.setCreaetTime(new Date());
        newsMapper.insert(news);
    }

    public void updateNews(PortalNewsVo news,UcUserInfo userInfo){
        BsPortalNews theNews =newsMapper.findById(news.getNewsId());
        BeanUtils.copyProperties(news,theNews);
        theNews.setUpdateBy(userInfo.getId());
        theNews.setUpdateTime(new Date());
        newsMapper.update(theNews);
    }

    public Page<BsPortalNews> findNewsList(FindPortalNewVo vo)  {
        Page<BsPortalNews> result = PageHelper.startPage(vo.getPageNum(),vo.getPageSize());
        newsMapper.findNewsList(vo);
        return result;

    }
}
